Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor config entities and arguments #831

Merged
merged 15 commits into from
Jun 3, 2020
Merged

Refactor config entities and arguments #831

merged 15 commits into from
Jun 3, 2020

Conversation

jan-goral
Copy link
Contributor

@jan-goral jan-goral commented Jun 2, 2020

This is a part of #718

Goals:

  1. Unification of yaml entities and cli options as both do the same there was no reason to keep them separately.
  2. Reduction of redundant code between AndroidArgs and IosArgs.
  3. Convertion of AndroidArgs and IosArgs to data classes.
  4. Extraction of factory methods and validators.

Test Plan

How do we know the code works?

This refactor of cli options, yaml config, AndroidArgs and IosArgs. It doesn't bring any features or changes so the existing unit tests should cover possible regression.

Checklist

  • Documented
  • Unit tested
  • release_notes.md updated

@jan-goral jan-goral self-assigned this Jun 2, 2020
@codecov-commenter
Copy link

codecov-commenter commented Jun 2, 2020

Codecov Report

Merging #831 into master will increase coverage by 1.01%.
The diff coverage is 93.78%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #831      +/-   ##
============================================
+ Coverage     80.14%   81.15%   +1.01%     
+ Complexity      674      637      -37     
============================================
  Files           151      166      +15     
  Lines          3087     3226     +139     
  Branches        443      463      +20     
============================================
+ Hits           2474     2618     +144     
- Misses          336      343       +7     
+ Partials        277      265      -12     

@jan-goral jan-goral changed the title Refactor Args Refactor config entities and arguments Jun 2, 2020
@jan-goral jan-goral marked this pull request as ready for review June 2, 2020 01:57
if (smartFlankGcsPath.count { it == '/' } <= 2 || !smartFlankGcsPath.endsWith(".xml")) {
throw FlankFatalError("smart-flank-gcs-path must be in the format gs://bucket/foo.xml")
}
}
Copy link
Contributor

@piotradamczyk5 piotradamczyk5 Jun 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I prefer when instead of nested ifs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH me to. I will change this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private fun CommonArgs.assertSmartFlankGcsPath(): Unit = with(smartFlankGcsPath) {
    when {
        isEmpty() -> Unit

        startsWith(FtlConstants.GCS_PREFIX).not() -> throw FlankFatalError(
            "smart-flank-gcs-path must start with gs://"
        )

        count { it == '/' } <= 2 || endsWith(".xml").not() -> throw FlankFatalError(
            "smart-flank-gcs-path must be in the format gs://bucket/foo.xml"
        )
    }
}

"which don't support ansi codes, to avoid corrupted output use `single` or `verbose`."]
)
var outputStyle: String? = null
// Flank specific

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line not needed :)


override val map = mapOf(
"gcloud" to keys
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be single line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rights, I was trying to keep one convention for maps and keys in all configs. Anyway this probably shouldn't be map, rather simple pair, same about another configs.

fun deviceMap(map: Map<String, String>?) {
if (map.isNullOrEmpty()) return
val androidDevice = Device(
model = map.getOrDefault("model", FtlConstants.defaultAndroidModel),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use "model","version" etc in IosArgs and Android args. Maybe we should move keys to const/enums?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, why not

Copy link
Contributor Author

@jan-goral jan-goral Jun 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, if both android and ios gcloud config has common device option probably it should be in CommonGcloudConfig.

config: IosConfig? = null,
gcloud: IosGcloudConfig = config!!.platform.gcloud,
flank: IosFlankConfig = config!!.platform.flank,
commonArgs: CommonArgs = config!!.common.createCommonArgs(config.data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a little bit unclear for me, config is nullable, but later on we declare that it is not null. So probably IosConfig is not nullable type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it doesn't looks well and should be explained, config is nullable cause when gcloud, flank, commonArgs are set explicit the config is redundant from logical perspective. Possible solution to get rid of null is:

fun createIosArgs(
    config: IosConfig
) = createIosArgs(
    gcloud = config.platform.gcloud,
    flank = config.platform.flank,
    commonArgs = config.common.createCommonArgs(config.data)
)

private fun createIosArgs(
    gcloud: IosGcloudConfig,
    flank: IosFlankConfig,
    commonArgs: CommonArgs
) = IosArgs(
    commonArgs = commonArgs,
    xctestrunZip = gcloud.test!!.processFilePath("from test"),
    xctestrunFile = gcloud.xctestrunFile!!.processFilePath("from xctestrun-file"),
    xcodeVersion = gcloud.xcodeVersion,
    devices = gcloud.device!!,
    testTargets = flank.testTargets!!.filterNotNull()
)

But it gives 2 functions instead of 1 and more lines. I'm am not sure which is better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for me 2 functions looks much better

FlankTestMethod(it, ignored = false)
},
this
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would format it

private fun IosArgs.calculateShardChunks() =
    if (disableSharding) listOf(emptyList())
    else ArgsHelper.calculateShards(
        filteredTests = filterTests(Xctestrun.findTestNames(xctestrunFile), testTargets)
            .distinct()
            .map { FlankTestMethod(it, ignored = false) },
        args = this
    )

maxTestShards !in IArgs.AVAILABLE_SHARD_COUNT_RANGE &&
maxTestShards != -1
) throw FlankFatalError(
"max-test-shards must be >= 1 and <= 50, or -1. But current is $maxTestShards"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use IArgs.AVAILABLE_SHARD_COUNT_RANGE.first / IArgs.AVAILABLE_SHARD_COUNT_RANGE.last in exception message.

@@ -19,3 +23,19 @@ data class Device(
orientation: $orientation""".trimStartLine()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you don't change this line but:

override fun toString(): String {
        return """
        - model: $model
          version: $version
          locale: $locale
          orientation: $orientation""".trimStartLine()
    }

vs

override fun toString() = """
        - model: $model
          version: $version
          locale: $locale
          orientation: $orientation""".trimStartLine()

This only for discussion to keep one style. Personally I prefer second.

@jan-goral jan-goral merged commit acd142d into master Jun 3, 2020
@jan-goral jan-goral deleted the refactor-args branch June 3, 2020 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants